$('.right-titleicon').on("click", function(e) {
	projectVM.showMenulist()
})
var dtPicker,dtPicker1;
var mask = mui.createMask();
projectVM = new Vue({
	el: "#content",
		    filters:{
		      times: function (dataStr,showhours){
		       var time = new Date(dataStr);
		          
		            function timeAdd0(str) {
		              if (str < 10) {
		                str = '0' + str;
		              }
		              return str
		            }
		            var y = time.getFullYear();
		            var m = time.getMonth() + 1;
		            var d = time.getDate();
		            var h = time.getHours();
		            var mm = time.getMinutes();
		            var s = time.getSeconds();
					if(showhours){
						return y + '-' + timeAdd0(m) + '-' + timeAdd0(d) +' ' + timeAdd0(h) + ':'+ timeAdd0(mm) + ':' + timeAdd0(s);
					}
		            return y + '-' + timeAdd0(m) + '-' + timeAdd0(d) ;
		      },
	},
	components: {
		
		personselect,
		processlog
	},
	data: {
		showAdd: false,
		id: '',
		menuList: [{
			name: '交班',
			path: 'handOver.html'
		}, {
			name: '接班',
			path: 'carryOn.html'
		}, {
			name: '列表',
			path: 'index.html'
		}, ],
		phenomenonTxt: '',
		fileIdsTraining: '',
		fileIds: '',
		userInfo: '',
		isSingle: true,
		trainId: '',
		filesList: [],
		trainingfileList: [],
		drill: {
			reviewTime:'',
			makeTime:''
		},
		showGoon:false,
		trainingDrill: {
			activityType:'',
			nodeCreateTime:'',
			trainingSource:null
		},
		phenomenon: [],
		advance:'',
		showBack:false,
		changeValue: 1,
		checked: [],
		showSubmit: false,
		backlist:[],
		backNode:'',
		onStatus: '',
		result: '',
		showMenu: false,
		showMorebtn: false,
		abc: '1111',
		activityAttachIds: '',
		advance: '',
		id: '',
		workStatus: '',
		nextWorkStatus: '',
		show_popup: false,
		list: [{
				content: 'XXX信用XXXX钥匙',
				status: 1,
				user: '[IP123456]张三2021-6-20'
			},
			{
				content: 'XXX信用XXXX钥匙',
				status: 2,
				user: '[IP123456]张三2021-6-20'
			},
			{
				content: 'XXX信用XXXX钥匙',
				status: 3,
				user: '[IP123456]张三2021-6-20'
			}
		],
		reviewDict:{}, //P627874 演练效果评审码表
		//P628874 选项列表节点选中
		drillInfo:{
			suitableInfo:'', //适宜性
			sufficiencyInfo:'',//充分性
			personPlaceInfo:'',//人员到位情况
			materialPlaceInfo:'',//现场物资
			personProtectInfo:'',//个人防护
			overallOrgizationInfo:'',//整体组织
			rescueGroupInfo:'',//抢险组分工
			practicalEffectInfo:'',//实战效果评价
			reportSuperiorInfo:'',//报告上级
			medicalResueInfo:'',//医疗救援部门
			governmentLeaveInfo:'' //政府周边撤离配合
		},
		proscessLogList:[],
		fileList:[],
		activeType:'' //记录原始数据
	},
	computed:{
		backlists(){
			// 退回节点过滤
			if(!this.activityTypeShow){
				
				let itemValueList = ["45","46","55"];
				// 	非应急演练
				return this.backlist.filter((item)=>{
					if(!itemValueList.includes(item.itemValue)){
						return item;
					}
				})
			}
			return this.backlist;
		},
		activityTypeShow(){
			// 应急演练显示
			if(this.trainingDrill && this.trainingDrill.activityType == 10){
				return true;
			}else{
				return false
			}
		},
		activityNov(){
			// 反事故演习和事故预想
			if(this.trainingDrill && (this.trainingDrill.activityType == 11||this.trainingDrill.activityType == 12)){
				return true;
			}else{
				return false
			}
			
		},
		emergencyDrillType(){
			// 应急演练类别
			let findValue = this.reviewDict.EMERGENCY_DRILL_TYPE ? this.reviewDict.EMERGENCY_DRILL_TYPE.find(item=> item.itemValue == this.trainingDrill.emergencyDrillType) : '';
			return findValue && findValue.itemText || '';
		},
		isCreated(){
			// 领取任务还是自己创建
			// 0:总部 1:分公司 2:场站
			if(this.trainingDrill && this.trainingDrill.trainingSource!=null){
				if(this.trainingDrill.trainingSource == '2'){
					return true;
				}else{
					return false;
				}
			}else{
				if(this.trainingDrill.orgLevel!=null){
					if(this.trainingDrill.orgLevel == '1' || this.trainingDrill.orgLevel == '0'){
						return false
					}
				}
				return true;
			}
			return true; //自己创建
		},
		isback(){
			// 是否退回到方案制定
			if(this.proscessLogList && this.proscessLogList.length){
				if(this.proscessLogList.length > 3){
					return true;
				}else{
					return false;
				}
			}
			return false;
		}
	},
	mounted: function() {
		mui.init()
		// 时间选择器
	    dtPicker = new mui.DtPicker({
		  type:'datetime'
		});
		
		 dtPicker1 = new mui.DtPicker({
		   type:'date'
		 });
		this.id = JSON.parse(localStorage.getItem('todoWork')).obj.regularWorkTaskConfigId
		this.workId = JSON.parse(localStorage.getItem('todoWork')).obj.workId
		this.workStatus = JSON.parse(localStorage.getItem('todoWork')).obj.workStatus
		this.nextWorkStatus = JSON.parse(localStorage.getItem('todoWork')).obj.nextWorkStatus
		this.userInfo = JSON.parse(localStorage.getItem("neiosUser"))
		console.log('--------当前节点workStatus：'+this.workStatus);
		console.log('--------下个workStatus：'+this.nextWorkStatus);
		console.log('获取local'+this.workId)
		this.getDate();
		
		let dictCodes = 'EMERGENCY_BACK_NODES';
		// 获取演练效果评审列表码表
		dictCodes += ',ACTIVITY_TYPE,EMERGENCY_DRILL_TYPE,EMERGENCY_OVERALL_APPRAISEINFO,EMERGENCY_SUITABLE_INFO,EMERGENCY_SUFFICIENCY_INFO,EMERGENCY_PERSON_PLACE,EMERGENCY_OVERALL_ORGNIZATION,EMERGENCY_PERSON_PROTECT,EMERGENCY_RESCUE_GROUP,EMERGENCY_PRACTICAL_EFFECT,EMERGENCY_REPORT_SUPERIOR,EMERGENCY_MEDICAL_RESCUE,EMERGENCY_GOVERNMENT_LEAVE,EMERGENCY_MATERIAL_PLACE'
		
		let dict = mui.neiosCommon.queryDict(dictCodes, (data) => {
			if (data != '') {
				this.backlist = data.EMERGENCY_BACK_NODES;
				this.reviewDict = data;
			}
		})
		this.getNodeListDetail();
	},
	methods: {
		delfileList(data){
			let that = this;
			let myFileIds = that.fileList.map((item)=>{
				return item.fileId
			});
			myFileIds.splice(myFileIds.findIndex(item => item === data.fileId), 1);
			this.activityAttachIds = myFileIds.join(',');
			// console.log(myFileIds.join(','))
			mui.neiosRequst.httpRequst('/app/common/getFileList', {fileIds:myFileIds.join(',')},
				function(data) {
					that.fileList = data.data;
					this.activityAttachIds = (data.data.map((item)=>{
						return item.fileId
					}).join(','))
				},
				function() {
					console.log("查询失败!");
				}
			);
		},
		fileListUpload(e) {
			let that = this;
			
			mui.neiosCommon.doUploads(function(ret) {
				if ("0" == ret.code) {
					console.log(JSON.stringify(ret))
					that.fileList.push(ret.data);
					let filesid = that.fileList.map((item)=>{
						return item.fileId
					});
					mui.neiosRequst.httpRequst('/app/common/getFileList', {fileIds:filesid.join(',')},
						function(data) {
							that.fileList = data.data;
							if(data.data && data.data.length ){
								that.activityAttachIds = (data.data.map((item)=>{
									return item.fileId
								}).join(','));
							}
							
						},
						function() {
							console.log("查询失败!");
						}
					);
					
				} else {
					mui.toast('文件上传失败');
				}
			}, function(err) {
				mui.toast('文件上传失败');
			})
		},
		getNodeListDetail(){
			let _this = this;
			
			mui.neiosRequst.httpRequst('/app/personWork/getNodeLogByWorkId', {
				workId:this.workId,
				workType:'0302'
			},
				function(data) {
					
					if (data.code == '0') {
						if (!data.data) {
							_this.proscessLogList = []
						} else {
							_this.proscessLogList = data.data
						}
					} else {
						_this.proscessLogList = []
						mui.toast('请稍后重试！')
					}
					console.log("----节点信息："+JSON.stringify(_this.proscessLogList))
				},
				function(e) {
					_this.proscessLogList = [];
				
					mui.toast('请稍后重试！')
				},'0'
			);
		},
		changeTime(key,can){	
			if(can) return;
			let _this = this;
			let k = key.split('.');
			dtPicker.show(function (selectItems) {
				let selectTime = selectItems.y.value + '-' + selectItems.m.value + '-' + selectItems.d.value + ' ' + selectItems.h.value + ':' + selectItems.i.value + ':00' ;
				_this[k[0]][k[1]] = selectTime;	
			 })
		},
		changePickerTime(key,isdisabled){
			if(isdisabled) return;
			let _this = this;
			let k = key.split('.');
			
			dtPicker1.show(function (selectItems) {
				let selectTime = selectItems.y.value + '-' + selectItems.m.value + '-' + selectItems.d.value + ' ' + selectItems.h.value + ':' + selectItems.i.value ;
				if(_this[k[0]]){
					_this[k[0]][k[1]] = selectTime;	
				}
				console.log(_this.drill)
				
			 })
		},
		//转时间戳
		dateToTimestamp(dateStr) {
			if (!dateStr) {
				return ''
			}
			let newDataStr = dateStr.replace(/\.|\-/g, '/')
			let date = new Date(newDataStr);
			let timestamp = date.getTime();
			return timestamp
		},
		//时间戳转换
				toDate(dataStr){
					var time = new Date(dataStr);
					   
					     function timeAdd0(str) {
					       if (str < 10) {
					         str = '0' + str;
					       }
					       return str
					     }
					     var y = time.getFullYear();
					     var m = time.getMonth() + 1;
					     var d = time.getDate();
					     var h = time.getHours();
					     var mm = time.getMinutes();
					     var s = time.getSeconds(); 
					     return y + '-' + timeAdd0(m) + '-' + timeAdd0(d) ;
				},
				hideBack(){
						this.showBack = false
				},
				showBacknode(){
						this.showBack = true
				},
		//退回
		sendBack(){
				if(this.advance == ''){
					mui.toast('请输入退回意见')
					return
				}
				else if (this.backNode == '' || !this.backNode || this.backNode == null){
					mui.toast('请选择退回节点')
					return
				}
				var param = {
					approveDes:this.advance,
					backNode:this.backNode,
					forwardNode:'1',
					nodeDealStaffCode:this.userInfo.userId,
					nodeDealStaffName:this.userInfo.name,
					nodeDealStaffRole:'0',
					nodeVisibleRange:'20',
					workId:this.workId,
					workType:'0302'
				}
				console.log('-----退回参数打印：' + JSON.stringify(param));
				mui.neiosRequst.httpRequst('/app/personWork/sendBack', param,
				function(data) {
					mui.toast('操作成功')
					let page = plus.webview.getWebviewById(
					"../sitOperation/terminalwork/terminalwork.html");
					let pageId = plus.webview.getWebviewById(page.id);
					let param = {}
					param.isRefresh = true
					mui.fire(pageId, 'isRefresh', param);
					setTimeout(function() {
						mui.back()
					}, 500);
				},
				function() {
					console.log("查询失败!");
				}) 
		},
		//回显操作人
		changePerson() {
			this.$nextTick(()=>{
				if(!this.drill)return;
				if(this.drill.staffCode && this.$refs.personselect_join){
					this.$refs.personselect_join.personids = this.drill.staffCode
					this.$refs.personselect_join.person = this.allName(this.drill.staffCode, this.drill.staffName)
				}
				if(this.drillInfo.problemStaffCode && this.$refs.personselect_find){
					this.$refs.personselect_find.personids = this.drillInfo.problemStaffCode
					this.$refs.personselect_find.person = this.allName(this.drillInfo.problemStaffCode, this.drillInfo
						.problemStaffName)
				}
				if(this.drillInfo.suitableReviewStaffCode && this.$refs.personselect_dill){
					this.$refs.personselect_dill.personids = this.drillInfo.suitableReviewStaffCode
					this.$refs.personselect_dill.person = this.allName(this.drillInfo.suitableReviewStaffCode, this.drillInfo.suitableReviewStaffName)
				}
				if(this.drillInfo.effectVerifiedStaffCode && this.$refs.personselect_verif){
					this.$refs.personselect_verif.personids = this.drillInfo.effectVerifiedStaffCode
					this.$refs.personselect_verif.person = this.allName(this.drillInfo.effectVerifiedStaffCode, this.drillInfo.effectVerifiedStaffName)
				}
				if(this.drillInfo.overallAppraiseStaffCode && this.$refs.personselect_allperson){
					this.$refs.personselect_allperson.personids = this.drillInfo.overallAppraiseStaffCode
					this.$refs.personselect_allperson.person = this.allName(this.drillInfo.overallAppraiseStaffCode, this.drillInfo.overallAppraiseStaffName)
				}
				if(this.drillInfo.appraiseStaffCode && this.$refs.personselect_person){
					this.$refs.personselect_person.personids = this.drillInfo.appraiseStaffCode
					this.$refs.personselect_person.person = this.allName(this.drillInfo.appraiseStaffCode, this
						.drillInfo.appraiseStaffName)
				}
				if(this.drill.tutelageStaffCode && this.$refs.personselect_jianhu){
					this.$refs.personselect_jianhu.personids = this.drill.tutelageStaffCode
					this.$refs.personselect_jianhu.person = this.allName(this.drill.tutelageStaffCode, this.drill
						.tutelageStaffName)
				}
				if(this.drill.reviewStaffCode && this.$refs.personselect){
					this.$refs.personselect.personids = this.drill.reviewStaffCode
					this.$refs.personselect.person = '[' + this.drill.reviewStaffCode + ']' + this.drill.reviewStaffName
				}
				if(this.drillInfo.processStaffCode && this.$refs.personselect_deal){
					this.$refs.personselect_deal.personids = this.drillInfo.processStaffCode
					this.$refs.personselect_deal.person = '[' + this.drillInfo.processStaffCode + ']' + this.drillInfo
						.processStaffName
				}
				if(this.drillInfo.stepsStaffCode && this.$refs.personselect_current){
					this.$refs.personselect_current.personids = this.drillInfo.stepsStaffCode
					this.$refs.personselect_current.person = '[' + this.drillInfo.stepsStaffCode + ']' + this.drillInfo
						.stepsStaffName
				}
				if(this.trainingDrill.nodeCreateStaffCode && this.$refs.personselect_issued){
					this.$refs.personselect_issued.personids = this.trainingDrill.nodeCreateStaffCode;
					this.$refs.personselect_issued.person = '[' + this.trainingDrill.nodeCreateStaffCode + ']' + this.trainingDrill.nodeCreateStaffName;
						
				}
			})

		},
		//获取多人员姓名
		filterNanme(e) {
			var arr = e.split(',')
			var list = []
			arr.forEach(item => {
				list.push(item.split(']')[1])
			})
			return list.join(',')
		},
		//合并多人员名称
		allName(e, f) {
			if (e == null || e == '' || f == null || f == '') {
				return ''
			}
			var a = e.split(',')
			var b = f.split(',')
			var c = []
			for (var i = 0; i < a.length; i++) {
				c.push('[' + a[i] + ']' + b[i])
			}
			return c.join(',')
		},
		//通过
		goOn(){
			if(this.workStatus == 60){
				if(this.$refs.personselect_goon.person == '' ){
					mui.toast('请选择审核人')
					return
				}
				// else if(this.advance == ''){
				// 	mui.toast('请输入意见')
				// 	return
				// }
			}
			
			var param = {
				approveDes:this.advance,
				currentUser:this.userInfo,
				nextWorkStatus:this.nextWorkStatus,
				workId:this.workId,
				workType:'0302'
			}
			if(this.workStatus == 60){
				param.nodeDealStaffCode= this.$refs.personselect_goon.personids
				param.nodeDealStaffName = this.$refs.personselect_goon.person.split(']')[1]
			}
			console.log(JSON.stringify(param))
			// return
			mui.neiosRequst.httpRequst('/app/tranEducation/submitDrill', param,
				function(data) {
					mui.toast('操作成功')
					let page = plus.webview.getWebviewById(
					"../sitOperation/terminalwork/terminalwork.html");
					let pageId = plus.webview.getWebviewById(page.id);
					let param = {}
					param.isRefresh = true
					mui.fire(pageId, 'isRefresh', param);
					setTimeout(function() {
						mui.back()
					}, 500);
				},
				function() {
					console.log("查询失败!");
				}
			);
		},
		//提交
		submit(param) {
			console.log(this.drillInfo.measure,this.workStatus)
			if((this.drillInfo.processInfo == '' || !this.drillInfo.processInfo) && this.workStatus == 20){
				mui.toast('请输入处理经过')
				return
			}
			else if((this.drillInfo.stepsInfo == '' ||  !this.drillInfo.stepsInfo)&& this.workStatus == 30){
				mui.toast('请输入正确处理步骤')
				return
			}
			else if((this.drillInfo.problemInfo == '' || !this.drillInfo.problemInfo) && this.workStatus == 40){
				mui.toast('请输入发现问题')
				return
			}
			else if((this.drillInfo.measure == '' || !this.drillInfo.measure) && this.workStatus == 40){
				mui.toast('请输入今后采取措施')
				return
			}
			else if(this.workStatus == 45){
				let list = [{
					value:'适宜性',
					key:'suitableInfo'
				},{
					value:'充分性',
					key:'sufficiencyInfo'
				},{
					value:'人员到位情况',
					key:'personPlaceInfo'
				},{
					value:'现场物资',
					key:'materialPlaceInfo'
				},{
					value:'个人防护',
					key:'personProtectInfo'
				},{
					value:'整体组织',
					key:'overallOrgizationInfo'
				},{
					value:'抢险组分工',
					key:'rescueGroupInfo'
				},{
					value:'实战效果评价',
					key:'practicalEffectInfo'
				},{
					value:'报告上级',
					key:'reportSuperiorInfo'
				},{
					value:'医疗救援部门',
					key:'medicalResueInfo'
				},{
					value:'周边政府撤离配合',
					key:'governmentLeaveInfo'
				}]
				let item = list.find(_=> !this.drillInfo[_.key]);
				if(item){
					mui.toast('请选择' + item.value + '!');
					return;
				}
			}
			else if((this.drillInfo.effectInfo == '' || !this.drillInfo.effectInfo) && this.workStatus == 46){
				mui.toast('请输入录入效果验证');
				return
			}
			else if(this.workStatus == 50){
				if(this.drillInfo.appraiseInfo == '' || !this.drillInfo.appraiseInfo){
					mui.toast('请输入个人评价');
					return
				}
				if(this.activityNov && (!this.fileList||this.fileList.length == 0)){
					console.log(this.activityNov)
					mui.toast('请至少上传一个附件');
					return;
				}
			}
			// else if(this.fileList.length == 0 && this.workStatus == 50){
			// 	mui.toast('请至少上传一个附件');
			// 	return
			// }
			else if(this.workStatus == 55){
				if(!this.drillInfo.overallAppraiseInfo){
					mui.toast('请选择总体评价');
					return
				}
				if(this.activityTypeShow && (!this.fileList || this.fileList.length == 0)){
					mui.toast('请至少上传一个附件');
					return;
				}
			}
			
			mask.show();//显示遮罩
			mui.neiosRequst.httpRequst('/app/tranEducation/submitDrill', param,
				function(data) {
					mui.toast('操作成功');
					mask.close()
					setTimeout(function() {
						let page2 = plus.webview.getWebviewById("../sitOperation/terminalwork/terminalwork.html");
						let param = {}
						param.isRefresh = true
						mui.fire(page2, 'isRefresh', param);
						mui.back()
					}, 200);
				},
				function() {
					console.log("查询失败!");
					mask.close()
				}
			);

		},
		//保存
		save(e) {
	
				if (e == 'submit') {
					if (this.$refs.personselect_join && this.$refs.personselect_join.personids == '') {
						mui.toast('请选择参加人员')
						return
					} else if (this.$refs.personselect && this.$refs.personselect.personids == '') {
						mui.toast('请选择审核人员')
						return
					} else if ( this.$refs.personselect_deal && this.$refs.personselect_deal.personids == '') {
						mui.toast('请选择处理经过录入人')
						return
					} else if ( this.$refs.personselect_current && this.$refs.personselect_current.personids == '') {
						mui.toast('请选择正确处理步骤录入人')
						return
					} else if (this.$refs.personselect_find && this.$refs.personselect_find.personids == '') {
						mui.toast('请选择发现问题及采取措施录入人')
						return
					} else if (this.$refs.personselect_person && this.$refs.personselect_person.personids == '') {
						mui.toast('请选择发现个人评价录入人')
						return
					} else if (this.$refs.personselect_jianhu && this.$refs.personselect_jianhu.personids == '') {
						mui.toast('请选择监护人')
						return
					} else if(this.$refs.personselect_dill && this.$refs.personselect_dill.personids == ''){
						mui.toast('请选择预案评审、演练效果评价录入人')
						return
					} else if(this.$refs.personselect_verif && this.$refs.personselect_verif.personids == ''){
						mui.toast('请选择效果验证录入人')
						return
					} else if(this.$refs.personselect_allperson && this.$refs.personselect_allperson.personids == ''){
						mui.toast('请选择总体评价录入人')
						return
					}



				}
				if(this.drillInfo){
					if(!('drillInfoId' in this.drillInfo)){
						this.drillInfo.drillInfoId = mui.neiosCommon.getUuidv4()
					}
				}
				
				// this.trainingDrill.nodeCreateStaffCode = this.$refs.personselect_issued.personids
				// this.trainingDrill.nodeCreateStaffName = this.$refs.personselect_issued.person.split(']')[1],
				// this.drill.nodeDealStaffCode= this.$refs.personselect.personids
				// this.drill.nodeDealStaffName = this.$refs.personselect.person.split(']')[1];
				if(this.$refs.personselect_join){
					this.drill.staffCode = this.$refs.personselect_join.personids || '';
					this.drill.staffName = this.filterNanme(this.$refs.personselect_join.person)
				}
				
				if(this.$refs.personselect){
					this.drill.reviewStaffCode = this.$refs.personselect.personids
					this.drill.reviewStaffName = this.$refs.personselect.person.split(']')[1]	
				}
				
				if(this.$refs.personselect_deal){
					this.drillInfo.processStaffCode = this.$refs.personselect_deal.personids;
					this.drillInfo.processStaffName = this.$refs.personselect_deal.person.split(']')[1];
				}
				
				if(this.$refs.personselect_jianhu){
					this.drill.tutelageStaffCode = this.$refs.personselect_jianhu.personids
					this.drill.tutelageStaffName = this.filterNanme(this.$refs.personselect_jianhu.person)
				}
				
				this.trainingDrill.dataSource = 'NEIOS_APP'+localStorage.getItem("currVersion")
				this.trainingDrill.workId = this.workId;
				console.log('保存'+ this.workId)
				this.drill.dataSource = 'NEIOS_APP'+localStorage.getItem("currVersion")
				this.drill.makeTime = new Date(this.drill.makeTime).getTime();
				this.drill.reviewTime = new Date(this.drill.reviewTime).getTime();
				this.drill.phenomenon = JSON.stringify(this.phenomenon);
				
				let {stepsStaffCode,stepsStaffName,problemStaffCode,problemStaffName,appraiseStaffCode,appraiseStaffName,overallAppraiseStaffCode,overallAppraiseStaffName,suitableReviewStaffName,suitableReviewStaffCode,effectVerifiedStaffCode,effectVerifiedStaffName} = {};
				if(this.$refs.personselect_current){
					stepsStaffCode = this.$refs.personselect_current.personids || '';
					stepsStaffName = this.$refs.personselect_current.person.split(']')[1];
				}
				if(this.$refs.personselect_find){
					problemStaffCode = this.$refs.personselect_find.personids
					problemStaffName = this.filterNanme(this.$refs.personselect_find.person)
				}
				if(this.$refs.personselect_person){
					appraiseStaffCode = this.$refs.personselect_person.personids;
					appraiseStaffName = this.filterNanme(this.$refs.personselect_person.person);
				}
				if(this.$refs.personselect_allperson){
					overallAppraiseStaffCode = this.$refs.personselect_allperson.personids
					overallAppraiseStaffName = this.filterNanme(this.$refs.personselect_allperson.person)
				}
				if(this.$refs.personselect_dill){
					suitableReviewStaffName = this.filterNanme(this.$refs.personselect_dill.person)
					suitableReviewStaffCode = this.$refs.personselect_dill.personids
				}
				
				if(this.$refs.personselect_verif){
					effectVerifiedStaffCode = this.$refs.personselect_verif.personids,
					effectVerifiedStaffName = this.filterNanme(this.$refs.personselect_verif.person)
				}
				var drillInfo1 = {
					processStaffCode : this.drillInfo.processStaffCode || '',
					processStaffName : this.drillInfo.processStaffName || '',
					processStallCodeName:this.$refs.personselect_deal ? this.$refs.personselect_deal.person : '',
					stepsStaffCode,
					stepsStaffName,
					problemStaffCode,
					problemStaffName,
					appraiseStaffCode,
					appraiseStaffName,
					dataSource : 'NEIOS_APP'+localStorage.getItem("currVersion"),
					activityType:this.trainingDrill.activityType,
					overallAppraiseStaffCode,
					overallAppraiseStaffName,
					suitableReviewStaffName,
					suitableReviewStaffCode,
					effectVerifiedStaffCode,
					effectVerifiedStaffName
				}
				this.drillInfo = Object.assign({},this.drillInfo,drillInfo1)
				
				
				// if (this.workStatus == 10) {
				// 	this.trainingDrill.status = 0
				// }
				// delete this.trainingDrill.orgLevel;
				this.trainingDrill.hostStaffCode = this.userInfo.userId
				this.trainingDrill.hostStaffName = this.userInfo.name
				
				let param = {
					trainingDrill: this.trainingDrill,
					drill: this.drill,
					drillInfo: this.drillInfo,
					phenomenonList: this.phenomenon,
					activityAttachIds: this.activityAttachIds,
					currentUser: this.userInfo,
					trainingAttachList: this.trainingfileList,
					nodeDealStaffCode: this.userInfo.userId,
					nodeDealStaffName: this.userInfo.name
				}
				
				if(!this.isCreated && !this.isback){
					// 首次下发
					this.trainingDrill.specialActivitieId = this.trainingDrill.trainingDrillId;
					
					param.trainingDrill = {
						'activityContent':this.trainingDrill.activityContent,
						'activityType':this.trainingDrill.activityType,
						'begTime':this.trainingDrill.begTime,
						'emergencyDrillType':this.trainingDrill.emergencyDrillType,
						'endTime':this.trainingDrill.endTime,
						'hostStaffCode':this.trainingDrill.hostStaffCode,
						'hostStaffName':this.trainingDrill.hostStaffName,
						'personPrepare':this.trainingDrill.personPrepare,
						'prepare':this.trainingDrill.prepare,
						'requirement':this.trainingDrill.requirement,
						'specialActivitieId':this.trainingDrill.specialActivitieId,
						'status':this.trainingDrill.status,
						'workId':this.trainingDrill.workId
					};
				}
				if (e == 'submit') {
					param.nextWorkStatus = this.nextWorkStatus
					param.workType = "0302"
					param.workId = this.workId;
					console.log('应急演练提交参数：'  + JSON.stringify(param));
					this.submit(param)
					return
				}
				console.log('应急演练仅保存参数：'  + JSON.stringify(param))
				mui.neiosRequst.httpRequst('/app/tranEducation/saveDrill', param,
					function(data) {
						mui.toast('操作成功')
					
						setTimeout(function() {
							location.reload()
						}, 500);
					},
					function() {
						console.log("查询失败!");
					}
				);

			},
		//添加现象
		confirmKey() {
			if (this.phenomenonTxt == '') {
				mui.toast('请输入现象')
			}
			this.phenomenon.push({
				number: this.phenomenon.length + 1,
				phenomenon: this.phenomenonTxt,
				phenomenonNo: '现象' + (this.phenomenon.length + 1)

			})
			this.showAdd = false
		},
		delKey(index,isdisabled){
			if(isdisabled)return;
			this.phenomenon.splice(index,1)
		},
		//隐藏弹窗
		hideAdd() {
			this.showAdd = ''
		},
		//获取当前时间
		getDate() {
			var date = new Date()
			var year = date.getFullYear()
			var month = date.getMonth() + 1
			var day = date.getDate()
			var hour = date.getHours()
			var min = date.getMinutes()

			if (month.toString().length < 2) {
				month = '0' + month
			}
			if (day.toString().length < 2) {
				day = '0' + day
			}
			if (hour.toString().length < 2) {
				hour = '0' + hour
			}
			if (min.toString().length < 2) {
				min = '0' + min
			}
			this.nowDate = year + '-' + month + '-' + day + ' ' + hour + ':' + min
			this.getDetailbyworkId()
		},
		//通过workId查询
		getDetailbyworkId() {
			let that = this
			let param = {
				workId: this.workId
			}
			mui.neiosRequst.httpRequst('/app/tranEducation/getDrillByWorkId', param,
				function(data) {
					
					if (data.data.trainingDrillId != null) {
						that.fileIds = data.data.fileIds
						that.fileIdsTraining = data.data.fileIdsTraining
						that.activeType = data.data.activityType;
						that.trainingDrill = data.data ? data.data : that.trainingDrill;
						that.drill = data.data.drill ? data.data.drill : that.drill;
						that.drillInfo = data.data.drillInfo ? data.data.drillInfo : that.drillInfo;
						if(data.data.drill && data.data.drill.phenomenon){
							that.phenomenon = JSON.parse(data.data.drill.phenomenon);
						}
						that.activityAttachIds = that.trainingDrill.activityAttachIds;
						console.log(JSON.stringify(data));
						
						// that.reviewDict = data.data.drillInfo;
						that.getFileList()
						that.getFileList('train');
						that.getFile();
						that.changePerson();
						

					} else {
						that.getDetail()
					}
				},
				function() {
					console.log("查询失败!");
				}
			);
		},
		getFile(){
			let _this = this;
			var param = {
				fileIds: this.trainingDrill.activityAttachIds
			}
			if(!this.trainingDrill.activityAttachIds)return;
			mui.neiosRequst.httpRequst('/app/common/getFileList', param,
			// mui.neiosRequst.httpRequst('/app/tranEducation/getTrainingFileIds', param,
				function(data) {
					_this.fileList = data.data;
					
				},
				function() {
					console.log("查询失败!");
				}
			
			);
		},
		
		//获取文件信息
		getFileList(e) {
			var that = this
			if (e == 'train') {
				if(this.fileIdsTraining =='' || this.fileIdsTraining == null){
					return
				}
				var param = {
					fileIds: this.fileIdsTraining
				}

				mui.neiosRequst.httpRequst('/app/common/getFileList', param,
					function(data) {
						that.trainingfileList = data.data
					},
					function() {
						console.log("查询失败!");
					}

				);
				return
			}
			if(this.fileIds =='' || this.fileIds == null){
				return
			}
			var param = {
				fileIds: this.fileIds
			}

			mui.neiosRequst.httpRequst('/app/common/getFileList', param,
				function(data) {
					that.filesList = data.data
				},
				function() {
					console.log("查询失败!");
				}
			);
		},
		//获取详情
		getDetail() {
			let that = this
			let param = {
				trainingDrillId: this.id
			}
			mui.neiosRequst.httpRequst('/app/tranEducation/getTrainingDrillById', param,
				function(data) {

					that.trainingDrill.hostStaffCode = that.userInfo.userId
					that.trainingDrill.hostStaffName = that.userInfo.name
					that.trainingDrill.hostStaffNameCode = '[' + that.userInfo.userId + ']' + that.userInfo
						.name
					that.trainingDrill.specialActiviteId = that.id
					that.activeType = data.data.activityType;
					that.trainingDrill.activityType = data.data.activityType
					that.trainingDrill.emergencyDrillType = data.data.emergencyDrillType //演练类型
					that.trainingDrill.activityContent = data.data.activityContent
					// that.trainingDrill = Object.assign({}, that.trainingDrill)
					that.trainingDrill = Object.assign({}, data.data)
					that.drill.makeTime = that.nowDate;
					
					// 参考资料
					that.fileIdsTraining = data.data.fileIdsTraining;
					that.getFileList('train')
					console.log(that.fileIdsTraining)

				},
				function() {
					console.log("查询失败!");
				}
			);
		},
		//返回上一页
		goBack() {
			mui.back()
		},
		//更多按钮
		showMore() {
			this.showMorebtn ? this.showMorebtn = false : this.showMorebtn = true
		},
		navTo(e) {
			mui.openWindow({
				url: e,
				id: e,
			});
		},
		// 上傳
		upload(e) {
			let that = this
			mui.neiosCommon.doUploads(function(ret) {
				if ("0" == ret.code) {
					// console.log("成功：" + JSON.stringify(ret))
					if(e == 'fujian'){
						that.fileIds == "" ? that.fileIds += ret.data.fileId : that.fileIds += "," + ret
							.data.fileId;
					that.getFileList()	
					}
					else{
						that.fileIdsTraining == "" ? that.fileIdsTraining += ret.data.fileId : that.fileIdsTraining += "," + ret
							.data.fileId;
							that.getFileList('train')
					}
					
				} else {
					mui.toast('文件上传失败');
				}
			}, function(err) {
				mui.toast('文件上传失败');
			})
		},
		// 删除文件
		delDown(data) {
			let myFileIds = this.fileIds.split(',')
			myFileIds.splice(myFileIds.findIndex(item => item.fileId === data.fileId), 1)
			this.fileIds = myFileIds.join(',')
			this.getFileds()
		},
		// 获取文件列表
		getFileds() {
			mui.neiosRequst.httpRequst('/app/common/getFileList', {
					fileIds: this.fileIds
				},
				(data) => {
					if (data.code == '0') {
						this.filesList = data.data
					} else {
						mui.toast("获取失败：" + data.msg);
					}
				},
				(data) => {
					mui.toast("退回失败：" + data.msg);
				}
			);
		},
		// 下载
		downLoad(data) {
			let url = "/app/common/downloadFile";
			let param = {};
			param.fileId = data.fileId;
			mui.neiosCommon.downLoadFile(param, function(ret) {
				mui.plusReady(function() {
					plus.nativeUI.closeWaiting();
				})
				//调用存储
				var callbackID = plus.bridge.callbackId(function(ret) {
					mui.toast(ret[0])
				}, function(err) {
					mui.toast('文件下载失败')
				});
				plus.bridge.execSync("FileHelper", "doFileSave", [callbackID, ret, data.fileName,
					"Argus3", "Argus4"
				])
			}, function(err) {
				mui.plusReady(function() {
					plus.nativeUI.closeWaiting();
				})
				mui.toast('文件下载失败')
			});
		},
		showTip(key){
			mui.toast(key)
		}
	},

})
mui.init();
$(function() {
	$("#dateSelect").click(function() {
		// 禁止修改时间
		return;
		var dtPicker = new mui.DtPicker({
			type: 'datetime'
		});
		dtPicker.show(function(selectItems) {
			// console.log(JSON.stringify(selectItems))
			$("#dateSelect").text(selectItems.text);
			projectVM.trainingDrill.begTime = selectItems.text

		})
	});
	$("#dateSelect1").click(function() {
		// 禁止修改时间
		return;
		var dtPicker = new mui.DtPicker({
			type: 'datetime'
		});
		dtPicker.show(function(selectItems) {

		 $("#dateSelect1").text(selectItems.text);
			projectVM.trainingDrill.endTime = selectItems.text
		})
	});
	$("#dateSelect3").click(function() {
		return;
		var dtPicker = new mui.DtPicker({
			type: 'datetime'
		});
		dtPicker.show(function(selectItems) {

			$("#dateSelect3").text(selectItems.text);
			projectVM.drill.reviewTime = selectItems.text

		})
	});
})
